package counter.com.baomidou.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import counter.com.baomidou.entity.Loudongpoc;
import counter.com.baomidou.entity.Serverinfo;
import counter.com.baomidou.service.ILoudongpocService;
import counter.com.common.Result;
import counter.com.connproperty.loudongjiance.PocAddProperty;
import counter.com.connproperty.loudongjiance.PocSearchProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author jobob
 * @since 2020-10-07
 */
@RestController
@RequestMapping("/loudongpoc")
public class LoudongpocController {
    @Autowired
    ILoudongpocService pocService;

    @PostMapping("/search")
    public Result search(@RequestBody PocSearchProperty data) {
        LambdaQueryWrapper<Loudongpoc> wrapper = new LambdaQueryWrapper<>();
        wrapper.orderByDesc(true, Loudongpoc::getId);
        Page<Loudongpoc> page = new Page<>(data.getPage(), data.getPagesize());
        IPage<Loudongpoc> iPage = pocService.page(page, wrapper);
        return Result.success(iPage);
    }

    @PostMapping("/add")
    public Result search(@RequestBody PocAddProperty data) {
        Loudongpoc loudongpoc = new Loudongpoc();
        loudongpoc.setName(data.getName());
        loudongpoc.setFilesize(data.getFilesize());
        loudongpoc.setDownloadurl(data.getDownloadurl());
        loudongpoc.setUid(data.getUid());
        loudongpoc.setUploadtime(LocalDateTime.now());
        if (pocService.save(loudongpoc)) {
            return Result.success("成功");
        } else {
            return Result.fail("失败");
        }
    }
}
